package models;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.trackvoodoo.models.AchivementsDocument.Achivements;
import com.trackvoodoo.models.AchivementsDocument.Achivements.Element;

import database.connector.DatabaseFactory;
import database.live.DOAStatements;
import database.live.MySqlDAO;

public class AchivementModel {

	private MySqlDAO d = null;
	private Achivements aModel = null;
	
	
	public AchivementModel()
	{
		d = (MySqlDAO) DatabaseFactory.getDAO();
		if (d.isOpen())
		{
			try{
				aModel = Achivements.Factory.newInstance();
				ResultSet rs = d.selectQuery(DOAStatements.SELECT_ACHIVEMENTS); //idachivement, internalName, description, instant, count, points, notJpg, gotJpg
				while (rs.next())
				{
					Element e = aModel.addNewElement();
					e.setId(rs.getInt(1));
					e.setInternalName(rs.getString(2));
					e.setDescription(rs.getString(3));
					e.setInstant(rs.getBoolean(4));
					e.setCount(rs.getInt(5));
					e.setPoints(rs.getInt(6));
					e.setNotJpg(rs.getString(7));
					e.setGotJpg(rs.getString(8));
				}
				
			}catch (SQLException e)
			{
				e.printStackTrace();
			}finally
			{
				d.closeConnection();
			}
		}
	}
	
	
	public Achivements getAchivementModel()
	{
		return aModel;
	}
}
